//
//  ViewController.m
//  23_QQ音乐
//
//  Created by 徐昊 on 16/8/15.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "MVModel.h"
#import "MVTableViewCell.h"
#import "MVData.h"
#import "MVContents.h"
#import "MVModel.h"
#import "MVSingers.h"
#define kTableViewCellName @"reuse"
#import "MVTableList.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *qq_MVTableView;
@property (nonatomic, strong) MVModel *mvModel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
}
- (void)handleData {
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    // 不使用自带的解析方式 自己进行解析
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    [session GET:@"http://i.y.qq.com/v8/fcg-bin/getmv_by_tag?cmd=mv_shows_new&format=jsonp&g_tk=5381&uin=0&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=h5&needNewCode=1&_=1470996835294&jsonpCallback=jsonp1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSData *data = responseObject;
        NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        dataStr = [dataStr stringByReplacingOccurrencesOfString:@"jsonp1(" withString:@""];
        dataStr = [dataStr substringToIndex:dataStr.length - 1];
        NSData *finalData = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error = nil;
        id reuslt = [NSJSONSerialization JSONObjectWithData:finalData options:NSJSONReadingMutableContainers error:&error];
        self.mvModel = [MVModel baseModelWithDic:reuslt];
        [_qq_MVTableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellName];
    cell.mvListArray = self.mvModel.data.contents.list[indexPath.section].mvlist;
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
